package _cache._ehcache;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

/**
 * @Author: huangya
 * @Date: 2020/6/20
 * @Description:
 */
public class EhcacheTest {

    public static void main(String[] args) {
        // 1. 创建缓存管理器
        CacheManager cacheManager = CacheManager.create(
                ClassLoader.getSystemResource("ehcache.xml"));
        // 2. 获取缓存对象
        Cache cache = cacheManager.getCache("ehcacheTest");
        // 3. 创建元素
        Element element = new Element("key1", "value1");
        // 4. 将元素添加到缓存
        cache.put(element);
        // 5. 获取缓存
        Element key1Element = cache.get("key1");
        System.out.println(key1Element);
        System.out.println(key1Element.getObjectValue());

    }
}
